/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// FunctionDecl.cpp: implementation of the CFunctionDecl class.
//
//////////////////////////////////////////////////////////////////////

#include "ssi_functiondecl.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFunctionDecl::CFunctionDecl()
{
  numParams = 0;
//  theGlobalFunction = SSI_NULL;
//  theClassFunction = SSI_NULL;

	theProcessor = SSI_NULL;
  objectPtr = SSI_NULL;
	dataPtr = 0;
  ReturnType = SSI_NULL;
  FunctionType = 0;
  Flags = 0;
	bIsDefined = 0;

	Access = ACCESS_GLOBAL;
}

CFunctionDecl::~CFunctionDecl()
{
  Types.Clear();
}

SSI_BOOL CFunctionDecl::operator ==(CFunctionDecl& Other)
{
  if(!(Other.Name == Name))
  {
    return 0;
  }
/*
	if(Other.getNumParams() != getNumParams()){
		return 0;
	}

	SSI_INT64 NumParams = getNumParams();
	SSI_INT64 Ctr = 0;
	for(Ctr = 0; Ctr < NumParams; Ctr++){
		if(getParamType(Ctr) != Other.getParamType(Ctr)){
			return 0;
		}
	}
*/

  return 1;
}

SSI_INT64 CFunctionDecl::addType(SSI_INT64 Type, String Name)
{
  FunctionParamTypeT aType;
  aType.Name = Name;
  aType.Type = Type;
  
  Types.push(aType);
  numParams++;
  return numParams;
}

SSI_INT64 CFunctionDecl::getParamType(SSI_INT64 Index)
{
  TypeNode* aNode = Types[Index];
  FunctionParamTypeT aType;

  if(aNode) 
  {
    aNode->Get(aType);
    return aType.Type;
  }
  else return SSI_NULL;  
}

String CFunctionDecl::getParamName(SSI_INT64 Index)
{
  TypeNode* aNode = Types[Index];
  FunctionParamTypeT aType;

  if(aNode) 
  {
    aNode->Get(aType);
    return aType.Name;
  }
  else return "";  
}

SSI_INT64 CFunctionDecl::getNumParams()
{
  return numParams;
}
bool CFunctionDecl::operator<(const CFunctionDecl& Other) const
{
  String myName = Name;
  String theirName = Other.Name;
  myName.ToUpper();
  theirName.ToUpper();
  return myName < theirName;
}

CFunctionDecl& CFunctionDecl::operator =(CFunctionDecl &Other)
{
  Types.Clear();

  Types = Other.Types;
   
	theProcessor = Other.theProcessor;
	
	objectPtr = Other.objectPtr;
  FunctionType = Other.FunctionType;
	dataPtr = Other.dataPtr;

  ReturnType = Other.ReturnType;
  Flags = Other.Flags;
	Access = Other.Access;

  Name = Other.Name;
	FileName = Other.FileName;
  numParams = Other.numParams;
  ScriptLines = Other.ScriptLines;

	bIsDefined = Other.bIsDefined;

	Package = Other.Package;

  return *this;
}

CFunctionDecl::CFunctionDecl(CFunctionDecl &Other)
: bIsDefined(0)
{
  Types.Clear();
  Types = Other.Types;
  
	theProcessor = Other.theProcessor;

  objectPtr = Other.objectPtr;
  FunctionType = Other.FunctionType;
	dataPtr = Other.dataPtr;

  ReturnType = Other.ReturnType;
  Flags = Other.Flags;
	Access = Other.Access;
  
  Name = Other.Name;
	FileName = Other.FileName;
  numParams = Other.numParams;

  ScriptLines = Other.ScriptLines;
	bIsDefined = Other.bIsDefined;

	Package = Other.Package;
}

void CFunctionDecl::SetProcessor(ProcessingFunctionPtr newProc)
{
	FunctionType = GLOBAL_FUNCTION_TYPE;
	theProcessor = newProc;
}

void CFunctionDecl::SetProcessor(GhostClass* ProcClass)
{
	FunctionType = ENGINE_FUNCTION_TYPE;
	objectPtr = ProcClass;
}

void CFunctionDecl::SetProcessor(CData* ProcData)
{
	FunctionType = CDATA_FUNCTION_TYPE;
	dataPtr = ProcData;
}

void CFunctionDecl::Clear()
{
  Name = "";
	FileName = "";
  numParams = 0;
  ReturnType = SSI_NULL;
	theProcessor = SSI_NULL;
	objectPtr = SSI_NULL;
  FunctionType = SSI_NULL;
  Flags = 0;
  Types.Clear();
}




